<template>
  <div class="product flex">
    <c-header :active="type" @changeType="getType"></c-header>
    <div class="title" v-if="productType == 0">产品中心-强化复合地板</div>
    <div class="title" v-else>产品中心-实木复合地板</div>
    <div class="main">
      <div class="product-type">
        <div
          :class="['product-type-li', productType == 0 ? 'product-type-active' : '']"
          @click="changeType(0)"
        >
          <img src="@/assets/img/product_type01.png" alt />
        </div>
        <div
          :class="['product-type-li', productType == 1 ? 'product-type-active' : '']"
          @click="changeType(1)"
        >
          <img src="@/assets/img/product_type02.png" alt style="width:2.39rem;height:0.25rem;" />
        </div>
      </div>
      <div class="tab">
        <van-collapse v-model="activeNames">
          <van-collapse-item title="产品总览" name="1">
            <van-cell
              :title="item.name"
              class="cell cell-color"
              v-for="(item, index) in tabArr"
              :key="index"
              :to="{path:'/product-details', query:{id: item.id, productType: productType, type:type}}"
              is-link
            />
          </van-collapse-item>
        </van-collapse>
        <div v-show="productType == 0">
          <van-cell
            title="结构及尺寸总览"
            is-link
            :to="{path:'/structureSize', query:{productType: productType, type:type}}"
          />
          <van-cell
            title="表面工艺"
            is-link
            :to="{path:'/surfaceWork', query:{productType: productType, type:type}}"
          />
          <van-cell
            title="质量等级"
            is-link
            :to="{path:'/qualityGrade', query:{productType: productType, type:type}}"
          />
        </div>
        <div v-show="productType == 1">
          <van-cell
            title="结构及尺寸总览"
            is-link
            :to="{path:'/structureSize', query:{productType: productType, type:type}}"
          />
          <van-cell
            title="表面工艺"
            is-link
            :to="{path:'/surfaceWork1', query:{productType: productType, type:type}}"
          />
          <van-cell
            title="木材分级"
            is-link
            :to="{path:'/woodGrade', query:{productType: productType, type:type}}"
          />
        </div>
      </div>
    </div>
    <c-footer :type="type" @changeType="getType"></c-footer>
  </div>
</template>

<script>
import { goodsCate } from "@/api/index";
import { Cell, Group } from "vux";
import { mapGetters } from "vuex";
export default {
  components: {
    Cell,
    Group
  },
  data() {
    return {
      tabArr: [],
      arr: [],
      productType: this.$route.query.productType
        ? this.$route.query.productType
        : 0,
      activeNames: ["0"]
    };
  },
  computed: {
    ...mapGetters(["type"])
  },
  created() {
    this.productTab();
  },
  watch: {
    $route() {
      this.productType = this.$route.query.productType;
      this.productTab();
    }
  },
  methods: {
    getType(type) {
      this.$store.dispatch("setType/getType", type);
    },
    productTab() {
      goodsCate().then(res => {
        const { code, msg, data } = res;
        if (code == 200) {
          this.arr = data.rows;
          this.tabArr = this.arr[this.productType];
        }
      });
    },
    changeType(type) {
      this.productType = type;
      this.tabArr = this.arr[type];
    }
  }
};
</script>
<style scoped>
.tab >>> .van-collapse-item__content {
  padding: 0 0 0 0.21rem;
}
</style>
<style lang="less" scoped>
.product {
  .cell-color {
    color: #6e6e6e;
  }

  .cell {
    font-size: 0.28rem;
  }

  .product-title {
    padding: 10px 15px;
    font-size: 0.28rem;
  }

  .product-type {
    height: 1.4rem;
    background: #fff;
    padding: 0 0.25rem;
    box-sizing: border-box;
    display: flex;
    justify-content: space-between;
    align-items: center;

    .product-type-li {
      height: 0.8rem;
      width: 3.34rem;
      display: flex;
      justify-content: center;
      align-items: center;
      border: 1px solid #e3e3e4;

      img {
        display: block;
        width: 2.94rem;
        height: 0.23rem;
      }
    }

    .product-type-active {
      border: 1px #000 solid;
      background: url(../../assets/img/active.png) no-repeat right bottom;
      background-size: 10%;
    }
  }

  .tab {
    margin-bottom: 0.27rem;
  }
}
</style>
